<?php
	require_once("conexion/conexion.php");
	//se pregunta para ver si viene de la pagina de bodega
	if(isset($_GET['producto']))
	{$prod = $_GET['producto'];}
	//echo $prod;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Formulario PSMB</title>
<link href="Estilos/global.css" rel="stylesheet" type="text/css" />
<link href="Estilos/local.css" rel="stylesheet" type="text/css" />
<link href="Estilos/CssTabla3.css" rel="stylesheet" type="text/css" />
<link href="Estilos/jquery.autocomplete.css" rel="stylesheet" type="text/css" />

<script src="include_js/jquery.js" type="text/javascript"></script>
<script src="include_js/jquery.autocomplete.js" type="text/javascript"></script>
<!--<script src="include_js/prototype.js" type="text/javascript"></script>
<script src="include_js/select_dependientes.js" type="text/javascript"></script>-->
<style>
.texto
{
	font-weight:bold;
	font-size:14px;
}
.borde
{
	border:0px solid #6593C0;
}
</style>
<script>
function CargarDocumentos(combo1,combo2,combo3,combo4,combo5)
{
	cmbDoc = document.getElementById(combo1).value;
	cmbPro = document.getElementById(combo2).value;
	cmbGasto = document.getElementById(combo4).value;
	cmbEGasto = document.getElementById(combo5).value;
	if((cmbDoc!='0')&&(cmbPro!='0')&&(cmbGasto!='0')&&(cmbEGasto!='0'))
	{
		if(cmbDoc=='1')
		{
			$.ajax({
            type: 'POST',
            url: 'Contabilidad/carga_ingresoDoc_factura.php',
            data: $('#form_ingreso_doc').serialize(),
            success: function(data) {
                $('#campos').html(data);
            	}
        	})
		}
		else
		{
			if(cmbDoc=='2')
			{
				$.ajax({
            	type: 'POST',
            	url: 'Contabilidad/carga_ingresoDoc_facturaExenta.php',
            	data: $('#form_ingreso_doc').serialize(),
            	success: function(data) {
                	$('#campos').html(data);
            		}
        		})
			}
			else
			{
				if(cmbDoc=='3')
				{
					$.ajax({
            		type: 'POST',
            		url: 'Contabilidad/carga_ingresoDoc_facturaElectronica.php',
            		data: $('#form_ingreso_doc').serialize(),
            		success: function(data) {
                		$('#campos').html(data);
            			}
        			})
				}
			}
		}
	}
	else
	{alert("Seleccione una opcion por cada item");}
}

function LimpiarCombo(combo)
{
	while(combo.length > 1)
	{
		combo.remove(combo.length-1);
	}
}

function LlenarCombo(json, combo, nombre)
{
	combo.options[0] = new Option(nombre, '0');
	for(var i=0;i<json.length;i++)
	{
		combo.options[combo.length] = new Option(json[i].data, json[i].id);
	} 
}

function SeleccionandoCombo(combo1, combo2, url, nombre)
{
	combo2 = document.getElementById(combo2);
	if(combo1.options[combo1.selectedIndex].value != "0")
	{
		LimpiarCombo(combo2);
		$.ajax({
			type: 'post',
			dataType: 'json',
			url: url,
			data: {valor: combo1.options[combo1.selectedIndex].value},
			success: function(json){
				LlenarCombo(json,combo2,nombre);
				combo2.disabled = false;
			}
		});
	}
	else
	{
		LimpiarCombo(combo2);
		combo2.disabled = true;
	}
}

function DesactivaCombo()
{
	document.getElementById('cmb_EGasto').disabled = true;
	document.getElementById('cmb_EGasto').value = 1;
}
</script>
</head>
<body>
<form name="form_ingreso_doc" id="form_ingreso_doc" method="post">
<div class='option2'><label style="font:Verdana, Arial, Helvetica, sans-serif; color:#0066CC; font-weight:bold;">Secci&oacute;n de Ingreso de Facturas.</label></div>
<div class='groupbox'>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
	<td class="borde"><div class="infopop"><label class="texto">Tipo Documento:</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	  <select name="cmb_Documento" id="cmb_Documento" style="width:170px">
        <option value="0">--DOCUMENTO--</option>
        <option value="1">FACTURA</option>
        <option value="2">FACTURA EXENTA</option>
        <option value="3">FACTURA ELECTR&Oacute;NICA</option>
      </select>
	</div></td>
	</tr>
  <tr>
    <td class="borde"><div class="infopop"><label class="texto">Proveedor:</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <select name="cmb_Proveedor" id="cmb_Proveedor">
         <option value="0">--PROVEEDOR--</option>
		  <?php
            	$con = new Conexion();
        		$con2 = $con->conexionBD("fpproduccion");
                $sql = "select ProvRut,ProvNombre from proveedor order by ProvNombre";
                $resultado = mysql_query($sql) or die ($con->error_mysql("Error en la consulta".mysql_error()));
				//$fila = mysql_num_rows($resultado);
				while ($row = mysql_fetch_row($resultado))
				{
					$dato = utf8_decode($row[1]);
					echo "<option value='".$row[0]."'>".$dato."</option>";
				}
                $con->cerrarBD();
		?>
      </select>
    </div></td>
	  </tr>
  <tr>
  	<td class="borde"><div class="infopop"><label class="texto">Tipo Cuenta:</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  	  <select name="cmb_Cuenta" id="cmb_Cuenta">
        <option value="CUENTA FP">CUENTA FP</option>
        <option value="CUENTA PERSONAL">CUENTA PERSONAL</option>
      </select>
  	</div></td>
	</tr>
  <tr>
    <td class="borde"><div class="infopop"><label class="texto">Area:</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <select name="cmb_Gasto" id="cmb_Gasto" >
        <option value="0">--AREA--</option>
         <?php
            	$con = new Conexion();
        		$con2 = $con->conexionBD("fpproduccion");
                $sql = "select ACod,ANombre from area order by ANombre";
                $resultado = mysql_query($sql) or die ($con->error_mysql("Error en la consulta".mysql_error()));
				//$fila = mysql_num_rows($resultado);
				while ($row = mysql_fetch_row($resultado))
				{
					echo "<option value='".$row[0]."'>".$row[1]."</option>";
				}
                $con->cerrarBD();
		?>
      </select>
    </div></td>
    </tr>
  <tr>
    <td class="borde"><div class="infopop"><label class="texto">Tipo Gasto:</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <select name="cmb_EGasto" id="cmb_EGasto">
        <option value="0">--GASTO--</option>
		<option value="1">PRODUCTO</option>
		 <?php
            	$con = new Conexion();
        		$con2 = $con->conexionBD("fpproduccion");
                $sql = "select TGCod,TGNombre from tipogasto where TGEstado=0 order by TGNombre";
                $resultado = mysql_query($sql) or die ($con->error_mysql("Error en la consulta".mysql_error()));
				//$fila = mysql_num_rows($resultado);
				while ($row = mysql_fetch_row($resultado))
				{
					echo "<option value='".$row[0]."'>".$row[1]."</option>";
				}
                $con->cerrarBD();
		?>
      </select>
    </div></td>
    </tr>
  
  <tr>
    <td class="borde"><div class="formtail"><input name="btn_Generar" id="btn_Generar" type="button" value="Ingresar Documento" onclick="CargarDocumentos('cmb_Documento','cmb_Proveedor','cmb_Cuenta','cmb_Gasto','cmb_EGasto');" /></div></td>
    </tr>
</table>
</div>
<?php 
		if($prod==1)
		{
			echo "<script>DesactivaCombo();</script>";
		}
	?>
	<input name="txtPagProd" id="txtPagProd" type="hidden" value="<?php echo $prod;?>"/>
</form>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td><div id="campos"></div></td></tr>
</table>
</body>
</html>